package com.pachong.frameworkdemo.demo.dialog;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.dialog.AlertDialogFragment;
import com.pachong.android.frameworkbase.dialog.EditDialogFragment;
import com.pachong.android.frameworkbase.dialog.IOSAlertDialogFragment;
import com.pachong.android.frameworkbase.dialog.IOSAlertListFragment;
import com.pachong.android.frameworkbase.utils.EasyToast;
import com.pachong.android.frameworkbase.utils.SLog;
import com.pachong.frameworkdemo.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class DialogDemoActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        setTitle("Dialog demo");
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_dialog_demo_index, null);
    }

    @OnClick(R.id.btnAll)
    public void onClickBtnShowDialog1() {
//        AlertFragment alertFragment = new AlertFragment();
//        alertFragment.show(getFragmentManager());

        final AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
        alertDialogFragment.setTitle("我是标题")
                .setMessage("M~e~s~s~a~g~e~!")
                .setNegativeButton(R.string.cancel, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "cancel clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .setPositiveButton(R.string.complete, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "OK clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .show(getSupportFragmentManager());

    }


    /**
     * 对话框按钮的焦点测试
     */
    @OnClick(R.id.btnFocusTest)
    public void onClickBtnFocusTest() {
        final AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
        alertDialogFragment.setTitle("biaoti")
                .setMessage("确定提交？")
                .setNegativeButton(R.string.cancel, false, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "cancel clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .setPositiveButton("确定", true, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "OK clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .show(getSupportFragmentManager());

    }


    @OnClick(R.id.btnNoTitle)
    public void onClickBtnShowDialog2() {
        final AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
        alertDialogFragment.setMessage("message")
                .setNegativeButton("cancel", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "cancel clicked");
                    }
                })
                .setPositiveButton("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "OK clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .show(getSupportFragmentManager());
    }

    @OnClick(R.id.btnNoCancel)
    public void onClickBtnShowDialog3() {
        final AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
        alertDialogFragment.setTitle(R.string.all_picture)
                .setMessage("message")
                .setPositiveButton("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "OK clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .show(getSupportFragmentManager());
    }


    @OnClick(R.id.btnIOSDialog1)
    public void onClickBtnIOS1() {

        final IOSAlertDialogFragment diaFrag = new IOSAlertDialogFragment();
        diaFrag.setTitle("title")
                .setActionButton("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "action button clicked");
                        diaFrag.dismiss();
                    }
                })
                .show(getSupportFragmentManager());
    }


    @OnClick(R.id.btnIOSDialog2)
    public void onClickBtnIOSDialog2() {

        String[] actionArr = new String[]{"测试1", "测试2", "测试3", "测试4"};
        final IOSAlertListFragment diaFrag = new IOSAlertListFragment();
        diaFrag.setActionList(new AdapterView.OnItemClickListener() {
                                  @Override
                                  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                      Log.e("vivi", "list action button clicked  position == " + position);
                                      diaFrag.dismiss();
                                  }
                              },
                actionArr)
                .show(getSupportFragmentManager());
    }


    @OnClick(R.id.btnCustomAlertDialog)
    public void onClickBtnCustomAlertDialog() {
        String prompt = "修改styles.xml中的AppPcfAlertDialog，layout替换成你自己的layout布局，注意layout里的控件id要使用已经定义好的@id";
        final AlertDialogFragment alertDialogFragment = new AlertDialogFragment();
        alertDialogFragment.setMessage(prompt)
                .setNegativeButton("cancel", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "cancel clicked");
                    }
                })
                .setPositiveButton("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SLog.e("vivi", "OK clicked");
                        alertDialogFragment.dismiss();
                    }
                })
                .show(getSupportFragmentManager());

    }

    @OnClick(R.id.btnEditText)
    public void onBtnEditTextClicked() {
        final EditDialogFragment alertDialogFragment = new EditDialogFragment();
        alertDialogFragment.setDefaultContent("DDDDDDDDDDDDDD")
                .setOnCententSavedListener(new EditDialogFragment.OnContentSavedListener() {
                    @Override
                    public void OnContentSaved(CharSequence content) {
                        EasyToast.showToast(DialogDemoActivity.this, "content = " + content);
                    }
                })
                .setNegativeButton("取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        alertDialogFragment.dismissAllowingStateLoss();
                    }
                })
                .setPositiveButton("确定", true, null)

        ;

        alertDialogFragment.show(getSupportFragmentManager());
    }


}